package com.dahuyou.tryy.too.parse.clazz.file.classpath.entry;

import com.dahuyou.tryy.too.parse.clazz.file.classpath.entry.impl.CompositeEntry;
import com.dahuyou.tryy.too.parse.clazz.file.classpath.entry.impl.DirectoryEntry;
import com.dahuyou.tryy.too.parse.clazz.file.classpath.entry.impl.JarOrZipEntry;
import com.dahuyou.tryy.too.parse.clazz.file.classpath.entry.impl.WildcardEntry;

import java.io.File;
import java.io.IOException;

/**
 * class查找入口路口抽象接口
 */
public interface Entry {
    byte[] readClass(String className) throws IOException;

    static Entry create(String path) {
        //File.pathSeparator；路径分隔符(win\linux)
        if (path.contains(File.pathSeparator)) {
            return new CompositeEntry(path);
        }
        if (path.endsWith("*")) {
            return new WildcardEntry(path);
        }
        if (path.endsWith(".jar") || path.endsWith(".JAR") ||
                path.endsWith(".zip") || path.endsWith(".ZIP")) {
            return new JarOrZipEntry(path);
        }
        return new DirectoryEntry(path);
    }

}
